﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace Hidistro.Core
{
    public class Log
    {
        private static string savePath = HttpContext.Current.Server.MapPath("~") + "/log/";

        private static bool isLog = true;
        
        public static void logSave(string strlog)
        {
            StreamWriter tStream;
            if (isLog == false)
                return;

            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            string nowData = DateTime.Now.ToShortDateString();

            string strFile = savePath + "juse.log";
            if (File.Exists(strFile))
            {
                FileInfo fileInfo = new FileInfo(strFile);
                if (fileInfo.Length > 1048576)
                {
                    File.Delete(strFile);
                    tStream = File.CreateText(strFile);
                }
                else
                    tStream = File.AppendText(strFile);
            }
            else
            {
                tStream = File.CreateText(strFile);
            }

            tStream.WriteLine("==" + DateTime.Now.ToString() + "==============================\r\n");
            tStream.Write(strlog + "\r\n");
            tStream.Flush();
            tStream.Close();

        }

    }
}
